package com.canaan.business.service.storehouse.impl;

import cn.hutool.core.collection.CollUtil;
import com.canaan.business.common.enums.basic.WhetherEnum;
import com.canaan.business.common.enums.inOutStock.InOutStockTypeEnum;
import com.canaan.business.common.enums.storehouse.*;
import com.canaan.business.domain.basic.WmsProduct;
import com.canaan.business.domain.basic.WmsStorehouse;
import com.canaan.business.domain.basic.WmsStorehouseLocation;
import com.canaan.business.domain.inOutStock.StorehouseStockCheck;
import com.canaan.business.domain.inOutStock.WmsInStockDetailOrder;
import com.canaan.business.domain.storehouse.*;
import com.canaan.business.mapper.storehouse.WmsInOutStorageMapper;
import com.canaan.business.service.basic.IWmsProductService;
import com.canaan.business.service.basic.IWmsStorehouseLocationService;
import com.canaan.business.service.basic.IWmsStorehouseService;
import com.canaan.business.service.inOutStock.IStorehouseStockCheckService;
import com.canaan.business.service.inOutStock.IWmsInStockDetailOrderService;
import com.canaan.business.service.storehouse.IStorehouseStockScrapService;
import com.canaan.business.service.storehouse.IWmsBarcodeRecordService;
import com.canaan.business.service.storehouse.IWmsInOutStorageService;
import com.canaan.business.service.storehouse.IWmsStorehouseStockService;
import com.canaan.common.exception.ServiceException;
import com.canaan.common.utils.DateUtils;
import com.canaan.common.utils.SecurityUtils;
import com.canaan.common.utils.StringUtils;
import com.canaan.common.utils.TableNoUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;


/**
 * 出入库记录Service业务层处理
 *
 * @author ruoyi
 * @date 2022-11-30
 */
@Service
public class WmsInOutStorageServiceImpl implements IWmsInOutStorageService
{
    @Resource
    private WmsInOutStorageMapper wmsInOutStorageMapper;

    @Resource
    private IWmsProductService wmsProductService;

    @Resource
    private IWmsStorehouseLocationService wmsStorehouseLocationService;

    @Resource
    private IWmsStorehouseService wmsStorehouseService;

    @Resource
    private IWmsStorehouseStockService wmsStorehouseStockService;

    @Resource
    private IWmsBarcodeRecordService wmsBarcodeRecordService;
    @Resource
    private IStorehouseStockScrapService storehouseStockScrapService;
    @Resource
    private IStorehouseStockCheckService storehouseStockCheckService;
    @Resource
    private IWmsInStockDetailOrderService wmsInStockDetailOrderService;

    /**
     * 查询出入库记录
     *
     * @param id 出入库记录主键
     * @return 出入库记录
     */
    @Override
    public WmsInOutStorage selectWmsInOutStorageById(Long id)
    {
        return wmsInOutStorageMapper.selectWmsInOutStorageById(id);
    }

    /**
     * 查询出入库记录列表
     *
     * @param wmsInOutStorage 出入库记录
     * @return 出入库记录
     */
    @Override
    public List<WmsInOutStorage> selectWmsInOutStorageList(WmsInOutStorage wmsInOutStorage)
    {
        return wmsInOutStorageMapper.selectWmsInOutStorageList(wmsInOutStorage);
    }

    /**
     * 新增出入库记录
     *
     * @param wmsInOutStorage 出入库记录
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int insertWmsInOutStorage(WmsInOutStorage wmsInOutStorage)
    {
        WmsProduct product = wmsProductService.selectWmsProductByProductNo(wmsInOutStorage.getProductNo());
        if(product == null){
            throw new ServiceException("物料编号在系统中不存在");
        }
        WmsStorehouse wmsStorehouse = wmsStorehouseService.selectWmsStorehouseByNo(wmsInOutStorage.getStorehouseNo());
        if(wmsStorehouse == null){
            throw new ServiceException("仓库编号在系统中不存在");
        }
        WmsStorehouseLocation location = wmsStorehouseLocationService.selectWmsStorehouseLocationByNo(wmsInOutStorage.getStorehouseLocationNo());
        if(location==null){
            throw new ServiceException("库位编号在系统中不存在");
        }

        WmsStorehouseStock storehouseStock = wmsStorehouseStockService.selectWmsStorehouseStockListByBarcode(wmsInOutStorage.getBarcode());
        StorehouseStockCheck check = storehouseStockCheckService.selectStorehouseStockCheckByBarcode(wmsInOutStorage.getBarcode());
        if(InOutStorageOperationEnum.OUT.getCode().equals(wmsInOutStorage.getOperation())){
            //出库校验
            if(StoreHouseTypeEnum.DJC.getCode().equals(wmsStorehouse.getTypeNo())){
                //待检库库存校验
                if(check == null) {
                    throw new ServiceException("该条码还未入库");
                }else if(check.getQty() < wmsInOutStorage.getQuantity()){
                    throw new ServiceException("出库数量不能大于库存数量");
                }
            }else {
                //普通库存校验
                if (storehouseStock == null) {
                    throw new ServiceException("该条码还未入库");
                } else if (storehouseStock.getQty() < wmsInOutStorage.getQuantity()) {
                    throw new ServiceException("出库数量不能大于库存数量");
                }
            }
        }else if(StoreHouseTypeEnum.DJC.getCode().equals(wmsStorehouse.getTypeNo())
                && InOutStorageOperationEnum.IN.getCode().equals(wmsInOutStorage.getOperation())
                && check != null && check.getStorehouseLocationNo() != null
                && !check.getStorehouseLocationNo().equals(wmsInOutStorage.getStorehouseLocationNo())){
            //待检库存入库，非报废入库校验
            throw new ServiceException("条码和库位不匹配");
        }else if(InOutStorageOperationEnum.IN.getCode().equals(wmsInOutStorage.getOperation())
                && storehouseStock != null && storehouseStock.getStorehouseLocationNo() != null
                && !storehouseStock.getStorehouseLocationNo().equals(wmsInOutStorage.getStorehouseLocationNo())){
            //非报废入库校验
            if(InOutStockTypeEnum.SCRAP.getCode()!=wmsInOutStorage.getType().intValue()){
                throw new ServiceException("条码和库位不匹配");
            }
        }
            wmsInOutStorage.setProductName(product.getProductName());
            wmsInOutStorage.setCreateBy(SecurityUtils.getUsername());
            wmsInOutStorage.setNo(TableNoUtil.getNo(WmsInOutStorage.class));
            wmsInOutStorage.setCreateTime(DateUtils.getNowDate());
            int response = wmsInOutStorageMapper.insertWmsInOutStorage(wmsInOutStorage);

            //关联处理库存信息
        if(InOutStockTypeEnum.WAIT_INSPECTION.getCode()==wmsInOutStorage.getType().intValue()){
            //处理待检仓入库库存
            WmsBarcodeRecord barcodeRecord = wmsBarcodeRecordService.selectLastBarcode(wmsInOutStorage.getBarcode());
            StorehouseStockCheck stockCheck = this.storehouseStockCheckService.selectStorehouseStockCheckByBarcode(wmsInOutStorage.getBarcode());
            if (stockCheck==null){
                stockCheck = new StorehouseStockCheck();
                stockCheck.setQty(wmsInOutStorage.getQuantity());
                Long validDateNum = barcodeRecord.getValidDateNum() == null ? null : barcodeRecord.getValidDateNum().longValue();
                //待检入库，新增待检仓库存就行
                stockCheck.setOrderNo(barcodeRecord.getOrderNo());
                stockCheck.setProductionDate(barcodeRecord.getProductionDate());
                stockCheck.setValidDateNum(validDateNum);
                stockCheck.setEffectiveDate(barcodeRecord.getEffectiveDate());
                stockCheck.setSupplierName(barcodeRecord.getSupplierName());
                stockCheck.setBatchNo(wmsInOutStorage.getBatchNo());
                stockCheck.setProductNo(wmsInOutStorage.getProductNo());
                stockCheck.setProductName(product.getProductName());
                stockCheck.setProductVersion(product.getProductVersion());
                stockCheck.setStorehouseNo(location.getStorehouseNo());
                stockCheck.setStorehouseAreaNo(location.getStorehouseAreaNo());
                stockCheck.setStorehouseLocationNo(location.getNo());
                stockCheck.setCompany(product.getCompany());
                stockCheck.setQualityMainTaskNo(wmsInOutStorage.getProductQualityMainTaskNo());
                stockCheck.setStatus(StorehouseStockCheckStatusEnum.TO_BE_INSPECTED.getCode());
                stockCheck.setBarcode(wmsInOutStorage.getBarcode());
                storehouseStockCheckService.insertStorehouseStockCheck(stockCheck);
            }else{
                stockCheck.setQty(stockCheck.getQty()+wmsInOutStorage.getQuantity());
                storehouseStockCheckService.updateStorehouseStockCheck(stockCheck);
            }

            return response;
        }else if(InOutStorageOperationEnum.IN.getCode().equals(wmsInOutStorage.getOperation()) && storehouseStock == null){
            WmsBarcodeRecord barcodeRecord = wmsBarcodeRecordService.selectLastBarcode(wmsInOutStorage.getBarcode());
            //新增库存
            storehouseStock = new WmsStorehouseStock();
            storehouseStock.setOrderNo(barcodeRecord.getOrderNo());
            storehouseStock.setContainerNo(wmsInOutStorage.getContainerNo());
            storehouseStock.setProductionDate(barcodeRecord.getProductionDate());
            storehouseStock.setValidDateNum(barcodeRecord.getValidDateNum());
            storehouseStock.setEffectiveDate(barcodeRecord.getEffectiveDate());
            storehouseStock.setSupplierName(barcodeRecord.getSupplierName());
            storehouseStock.setBatchNo(wmsInOutStorage.getBatchNo());
            storehouseStock.setBarcode(wmsInOutStorage.getBarcode());
            storehouseStock.setProductNo(wmsInOutStorage.getProductNo());
            storehouseStock.setProductName(product.getProductName());
            storehouseStock.setProductVersion(product.getProductVersion());
            storehouseStock.setQty(wmsInOutStorage.getQuantity());
            storehouseStock.setStorehouseNo(location.getStorehouseNo());
            storehouseStock.setStorehouseAreaNo(location.getStorehouseAreaNo());
            storehouseStock.setStorehouseLocationNo(location.getNo());
            storehouseStock.setCompany(product.getCompany());
            storehouseStock.setStatus(StorehouseStockStatusEnum.NORMAL.getCode());
            storehouseStock.setWorkOrderNo(wmsInOutStorage.getWorkNo());
            wmsStorehouseStockService.insertWmsStorehouseStock(storehouseStock);
            if(InOutStockTypeEnum.RECEIVING.getCode()==wmsInOutStorage.getType().intValue()) {
                //收货时有关联待检库存的处理,
                wmsInOutStorage.setType(InOutStockTypeEnum.WAIT_INSPECTION_OUT.getCode().longValue());
                wmsInOutStorage.setOperation(InOutStorageOperationEnum.OUT.getCode());
                this.waitingStockOperation(wmsInOutStorage, true);
            }
        }else{
            //当前库存数量
            Long stqty = storehouseStock == null ? 0L : storehouseStock.getQty();
            //出入库数量
            Long quantity = wmsInOutStorage.getQuantity();
            if (StringUtils.isNotEmpty(wmsInOutStorage.getWorkNo())){
                storehouseStock.setOrderNo(wmsInOutStorage.getWorkNo());
            }
            if(InOutStorageOperationEnum.OUT.getCode().equals(wmsInOutStorage.getOperation())){
                if(StoreHouseTypeEnum.DJC.getCode().equals(wmsStorehouse.getTypeNo())){
                    //待检库存操作
                    this.waitingStockOperation(wmsInOutStorage, false);
                    return response;
                }
                //出库扣减数量
                stqty = stqty-quantity;
                storehouseStock.setQty(stqty);
            }else{
                //报废入库
                if(InOutStockTypeEnum.SCRAP.getCode()==wmsInOutStorage.getType().intValue()){
                    stqty = stqty-quantity;
                    //默认生成一条出库流水记录
                    WmsInOutStorage inStorageSc = new WmsInOutStorage();
                    inStorageSc.setNo(TableNoUtil.getNo(WmsInOutStorage.class));
                    inStorageSc.setProductNo(wmsInOutStorage.getProductNo());
                    inStorageSc.setProductName(product.getProductName());
                    inStorageSc.setProductUnit(product.getCompany());
                    inStorageSc.setStorehouseNo(storehouseStock.getStorehouseNo());
                    inStorageSc.setAreaNo(wmsInOutStorage.getAreaNo());
                    inStorageSc.setStorehouseLocationNo(storehouseStock.getStorehouseLocationNo());
                    inStorageSc.setBatchNo(storehouseStock.getBatchNo());
                    inStorageSc.setBarcode(wmsInOutStorage.getBarcode());
                    inStorageSc.setQuantity(wmsInOutStorage.getQuantity());
                    inStorageSc.setRelNo(wmsInOutStorage.getRelNo());
                    inStorageSc.setType(InOutStockTypeEnum.SCRAP_OUT.getCode().longValue());
                    inStorageSc.setOperation(InOutStorageOperationEnum.OUT.getCode());
                    this.wmsInOutStorageMapper.insertWmsInOutStorage(inStorageSc);
                    storehouseStock.setQty(stqty);
                    //生成报废数据
                    WmsBarcodeRecord barcodeRecord = wmsBarcodeRecordService.selectLastBarcode(wmsInOutStorage.getBarcode());
                    if(barcodeRecord==null){
                        throw new ServiceException("条码不存在");
                    }
                    StorehouseStockScrap stockScrap = new StorehouseStockScrap();
                    stockScrap.setOrderNo(barcodeRecord.getOrderNo());
                    stockScrap.setProductionDate(barcodeRecord.getProductionDate());
                    stockScrap.setEffectiveDate(barcodeRecord.getEffectiveDate());
                    stockScrap.setSupplierName(barcodeRecord.getSupplierName());
                    stockScrap.setBarcode(wmsInOutStorage.getBarcode());
                    stockScrap.setBatchNo(wmsInOutStorage.getBatchNo());
                    stockScrap.setProductNo(wmsInOutStorage.getProductNo());
                    stockScrap.setProductName(product.getProductName());
                    stockScrap.setProductVersion(product.getProductVersion());
                    stockScrap.setQty(wmsInOutStorage.getQuantity());
                    stockScrap.setStorehouseNo(location.getStorehouseNo());
                    stockScrap.setStorehouseAreaNo(location.getStorehouseAreaNo());
                    stockScrap.setStorehouseLocationNo(location.getNo());
                    stockScrap.setCompany(product.getCompany());
                    stockScrap.setStatus(StorehouseStockStatusEnum.NORMAL.getCode());
                    storehouseStockScrapService.insertStorehouseStockScrap(stockScrap);
                }
                else if(InOutStockTypeEnum.RECEIVING.getCode()==wmsInOutStorage.getType().intValue()){
                    //收货时有关联待检的处理
                    WmsInStockDetailOrder detailOrder =  this.wmsInStockDetailOrderService.gettWmsInStockDetailOrderByPnAndOrderNo(wmsInOutStorage.getProductNo(),wmsInOutStorage.getBusinessNo());
                    if (detailOrder!=null){
                        if (detailOrder.getWhetherWaitProduct().intValue()!= WhetherEnum.Y.getCode()){
                            wmsInOutStorage.setType(InOutStockTypeEnum.WAIT_INSPECTION_OUT.getCode().longValue());
                            wmsInOutStorage.setOperation(InOutStorageOperationEnum.OUT.getCode());
                            this.waitingStockOperation(wmsInOutStorage, true);
                        }else{
                            storehouseStock.setQty(storehouseStock.getQty() + quantity);
                        }
                    }

                }else if(StoreHouseTypeEnum.DJC.getCode().equals(wmsStorehouse.getTypeNo())){
                    //待检库存操作
                    this.waitingStockOperation(wmsInOutStorage, false);
                    return response;
                }
                else{
                    storehouseStock.setQty(storehouseStock.getQty() + quantity);
                }
            }
            if (storehouseStock.getQty()>0){
                wmsStorehouseStockService.updateWmsStorehouseStock(storehouseStock);
            }else{
                //如果库存数量为0则将库存记录删除
                wmsStorehouseStockService.deleteWmsStorehouseStockById(storehouseStock.getId());
            }

        }

        return response;
    }

    @Override
    public int addWmsInOutStorage(WmsInOutStorage wmsInOutStorage) {
        wmsInOutStorage.setCreateBy(SecurityUtils.getUsername());
        wmsInOutStorage.setCreateTime(DateUtils.getNowDate());
        return this.wmsInOutStorageMapper.insertWmsInOutStorage(wmsInOutStorage);
    }

    /**
     * 扣减待检库对应的库存，根据条码
     * @param wmsInOutStorage   收货入库类型的记录
     * @param isInsertStorage   是否添加出入库记录
     */
    private void waitingStockOperation(WmsInOutStorage wmsInOutStorage, boolean isInsertStorage){
        StorehouseStockCheck stockCheck = storehouseStockCheckService.selectStorehouseStockCheckByBarcode(wmsInOutStorage.getBarcode());
        if (stockCheck != null) {
            //如果有找到对应的持仓库存就需要减去待检仓的库存数量
            if(isInsertStorage) {
                //判断是否需要插入出入库记录，要的话记录初始化插入
                WmsInOutStorage inStorageSj = new WmsInOutStorage();
                inStorageSj.setType(wmsInOutStorage.getType());
                inStorageSj.setNo(TableNoUtil.getNo(WmsInOutStorage.class));
                inStorageSj.setProductNo(stockCheck.getProductNo());
                inStorageSj.setProductName(stockCheck.getProductName());
                inStorageSj.setProductUnit(stockCheck.getCompany());
                inStorageSj.setStorehouseNo(stockCheck.getStorehouseNo());
                inStorageSj.setAreaNo(stockCheck.getStorehouseAreaNo());
                inStorageSj.setStorehouseLocationNo(stockCheck.getStorehouseLocationNo());
                inStorageSj.setBatchNo(stockCheck.getBatchNo());
                inStorageSj.setBarcode(stockCheck.getBarcode());
                inStorageSj.setQuantity(wmsInOutStorage.getQuantity());
                inStorageSj.setRelNo(wmsInOutStorage.getRelNo());
                inStorageSj.setOperation(wmsInOutStorage.getOperation());
                inStorageSj.setCreateBy(SecurityUtils.getUsername());
                inStorageSj.setCreateTime(new Date());
                this.wmsInOutStorageMapper.insertWmsInOutStorage(inStorageSj);
            }
            //扣减待检仓库存
            if(InOutStorageOperationEnum.OUT.getCode().equals(wmsInOutStorage.getOperation())){
                wmsInOutStorage.setQuantity(-wmsInOutStorage.getQuantity());
            }
            stockCheck.setQty(stockCheck.getQty() + wmsInOutStorage.getQuantity());
            if(stockCheck.getQty() < 1){
                //库存为0就删除
                storehouseStockCheckService.deleteStorehouseStockCheckById(stockCheck.getId());
                return;
            }
            storehouseStockCheckService.updateStorehouseStockCheck(stockCheck);
        }

    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public WmsInOutStorage insertWmsInOutStorageWithStock(WmsInOutStorage wmsInOutStorage){
        wmsInOutStorageMapper.insertWmsInOutStorage(wmsInOutStorage);
        WmsStorehouseStock storehouseStock = wmsStorehouseStockService.selectWmsStorehouseStockListByBarcode(wmsInOutStorage.getBarcode());
        if (storehouseStock != null) {
            if (InOutStorageOperationEnum.IN.getCode().equals(wmsInOutStorage.getOperation())){
                storehouseStock.setQty(storehouseStock.getQty()+wmsInOutStorage.getQuantity());
            } else {
                storehouseStock.setQty(storehouseStock.getQty()-wmsInOutStorage.getQuantity());
            }
            if (storehouseStock.getQty()>0){
                wmsStorehouseStockService.updateWmsStorehouseStock(storehouseStock);
            }else{
                wmsStorehouseStockService.deleteWmsStorehouseStockById(storehouseStock.getId());
            }
        }
        return wmsInOutStorage;
    }

    /**
     * 修改出入库记录
     *
     * @param wmsInOutStorage 出入库记录
     * @return 结果
     */
    @Override
    public int updateWmsInOutStorage(WmsInOutStorage wmsInOutStorage)
    {
        wmsInOutStorage.setUpdateBy(SecurityUtils.getUsername());
        wmsInOutStorage.setUpdateTime(DateUtils.getNowDate());
        return wmsInOutStorageMapper.updateWmsInOutStorage(wmsInOutStorage);
    }

    /**
     * 批量删除出入库记录
     *
     * @param ids 需要删除的出入库记录主键
     * @return 结果
     */
    @Override
    public int deleteWmsInOutStorageByIds(Long[] ids)
    {
        return wmsInOutStorageMapper.deleteWmsInOutStorageByIds(ids);
    }

    /**
     * 删除出入库记录信息
     *
     * @param id 出入库记录主键
     * @return 结果
     */
    @Override
    public int deleteWmsInOutStorageById(Long id)
    {
        return wmsInOutStorageMapper.deleteWmsInOutStorageById(id);
    }

    /**
     * 批量新增出入库记录
     *
     * @param inOutStorageList 出入库记录列表
     * @return 结果
     */
    @Override
    public int batchInsertInOutStorage(List<WmsInOutStorage> inOutStorageList) {
        String username = SecurityUtils.getUsername();
        Date currerTime = DateUtils.getNowDate();
        for (WmsInOutStorage inOutStorage : inOutStorageList){
            if(StringUtils.isBlank(inOutStorage.getNo())){
                inOutStorage.setNo(TableNoUtil.getNo(WmsInOutStorage.class));
            }
            inOutStorage.setCreateBy(username);
            inOutStorage.setCreateTime(currerTime);
        }
        int insertNum = 0;
        for (int i=0; i<inOutStorageList.size();) {
            int endIndex = i+500;
            if (endIndex > inOutStorageList.size()) {
                endIndex = inOutStorageList.size();
            }
            insertNum = insertNum + wmsInOutStorageMapper.batchInsertInOutStorage(inOutStorageList.subList(i, endIndex));
            i = endIndex;
        }
        return insertNum;
    }

    /**
     * 根据添加差异添加出入库记录
     * @author 梁建设
     * @since 2023/2/17 上午10:14
     */
    @Override
    public void insertCheckInOutStorage(List<StockCheckDiff> diffs) {
        List<WmsInOutStorage> storages = new ArrayList<>();
        for (StockCheckDiff diff : diffs) {
            if (diff.getCheckQty() == diff.getStockQty()) {
                continue;
            }
            WmsInOutStorage wmsInOutStorage = new WmsInOutStorage();
            wmsInOutStorage.setProductNo(diff.getProductNo());
            wmsInOutStorage.setProductName(diff.getProductName());
            wmsInOutStorage.setProductUnit(diff.getProductUnit());
            wmsInOutStorage.setQuantity(Math.abs(diff.getStockQty() - diff.getCheckQty()));
            wmsInOutStorage.setStorehouseLocationNo(diff.getLocationNo());
            wmsInOutStorage.setStorehouseNo(diff.getStorehouseNo());
            wmsInOutStorage.setAreaNo(diff.getAreaNo());
            wmsInOutStorage.setBarcode(diff.getBarcode());
            wmsInOutStorage.setRelNo(diff.getCheckNo());
            wmsInOutStorage.setType(diff.getStockQty() > diff.getCheckQty() ?
                    InOutStorageTypeEnum.CHECK_OUT.getCode() : InOutStorageTypeEnum.CHECK_IN.getCode());
            wmsInOutStorage.setOperation(diff.getStockQty() > diff.getCheckQty() ?
                    InOutStorageOperationEnum.OUT.getCode() : InOutStorageOperationEnum.IN.getCode());
            storages.add(wmsInOutStorage);
        }
        if (CollUtil.isNotEmpty(storages)) {
            this.batchInsertInOutStorage(storages);
        }
    }

    /**
     * 批量修改出入库记录
     *
     * @param inOutStorageList 出入库记录列表
     * @return 结果
     */
    @Override
    public int batchUpdateInOutStorage(List<WmsInOutStorage> inOutStorageList) {
        String username = SecurityUtils.getUsername();
        Date currerTime = DateUtils.getNowDate();
        for (WmsInOutStorage inOutStorage : inOutStorageList){
            inOutStorage.setUpdateBy(username);
            inOutStorage.setUpdateTime(currerTime);
        }
        int updateNum = 0;
        for (int i=0; i<inOutStorageList.size();) {
            int endIndex = i+500;
            if (endIndex > inOutStorageList.size()) {
                endIndex = inOutStorageList.size();
            }
            updateNum = updateNum + wmsInOutStorageMapper.batchUpdateInOutStorage(inOutStorageList.subList(i, endIndex));
            i = endIndex;
        }
        return updateNum;
    }
}
